package com.koron.order.defect.excel;

import com.alibaba.excel.converters.string.StringStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.koron.order.patrol.bean.po.PatrolStatus;

public class PatrolVOContractConvertor extends StringStringConverter {

    /**
     *
     * @param value 实际值
     * @param contentProperty 导出的属性实体对象
     * @param globalConfiguration
     * @return
     */
    @Override
    public WriteCellData<String> convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        // 获取属性名
        String fieldName = contentProperty.getField().getName();
        if ("status".equals(fieldName)) {
            value = PatrolStatus.getPatrolStatus(value).getDesc();
        }
        if ("arriveStatus".equals(fieldName)){
            value = Integer.valueOf(value) == 1 ? "已签到":"未签到";
        }
        if ("result".equals(fieldName)){
            value = getResultValue(value);
        }
        if ("runStatus".equals(fieldName)){
            value = getStatusValue(value);
        }
        return new WriteCellData<>(value==null?"":value);
    }

    private String getResultValue(String value) {
        String result = null;
        switch (value){
            case "0":
                result =  "检修";
                break;
            case "1":
                result = "正常";
                break;
            case "-1":
                result =  "异常";
                break;
        }
        return result != null ? result : " ";
    }


    private String getStatusValue(String value) {
        String result = null;
        switch (value){
            case "0":
                result =  "未运行";
                break;
            case "1":
                result = "运行中";
                break;
        }
        return result != null ? result : "-";
    }
}
